using Avalonia.Data.Converters;
using System;
using System.Globalization;

namespace SerialTool.Converters;

public static class ObjectConverters
{
    public static readonly IValueConverter NotEqual = 
        new FuncValueConverter<object?, bool>(p => !Equals(p, Convert.ChangeType(NotEqualConverterParameter, p?.GetType() ?? typeof(object))));
        
    // Helper property to store the converter parameter for NotEqual
    // This is a simplification; a more robust approach might involve a custom converter class.
    internal static object? NotEqualConverterParameter { get; set; }

    public static readonly IValueConverter IsNull = 
        new FuncValueConverter<object?, bool>(p => p == null);

    public static readonly IValueConverter IsNotNull = 
        new FuncValueConverter<object?, bool>(p => p != null);
}

// Custom converter to handle NotEqual with parameter properly
public class NotEqualConverter : IValueConverter
{
    public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return !Equals(value, parameter);
    }

    public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
} 